%% Dynamic Factor Model for Mixed Frequency Data
%  With Time-Varying Intercepts and Stochastic Volatility

% *** ITALY ***

clear
clc

addpath('functions');
addpath('data');
 
seed = RandStream('mt19937ar','Seed',1);
RandStream.setGlobalStream(seed);

%% Settings

% Data Adjustments

settings.panelsize = 19;

settings.remove_means = 1;
settings.standardise = 0;                               % Standardise all Variables Prior to estimation (optional)
settings.remove_outliers = 1;                           % Remove outliers following Stock and Watson (reccommended)

% Model Specification

settings.WhereQuarterly = [1:3];
settings.soft6 = [4:8];

settings.constant = 0;                                  % Add constant in VAR

settings.nf = 1;                                        % Number of latent factors

settings.p = 2;                                         % Maximum lag order of factor VAR
settings.s = 0;                                         % Maximum factor lags that load observables (0 = contemporaneous only)
settings.q = 2;                                         % Order of serial correlation in idiosyncratic components. Max = 5;

settings.vardiag = 0;



settings.SV_factors = 1;                                % Add Stochastic Volatility to the common factors (0 = no; 1 = yes);
settings.SV_idiosyncratic = 1;

% Gibss Sampler Setting

settings.nreps = 7000;       % Number of Gibbs Sampler Draws
settings.nburn = 2000;       % Discard the first nburn draws as Burn-in Draws

settings.show_plots = 0;
settings.plot_each = 100;

%% Bayesian Priors

settings.var_priors = 2;     % 0 = Noninformative; 1 = Independent N-IW;
settings.lambda_priors = 0;   % 0 = Noninformative; 1 = shrink towards zero
settings.rho_priors = 1;     % 0 = Noninformative; 1 = shrink towards zero

settings.prior_SV = 1E-4;
settings.prior_SV_sm = 1E-4;


%% Run DFM for Baseline Case

settings.trend = 2;
settings.schemenumber = 202;
settings.prior_trend = 0.001/2;

load('ADP_international_IT.mat');
yraw(:,[2,3]) = yraw(:,[3,2]); % Order should be Y, C, H
[results] = DFM_function3_Simple(settings,yraw,dates,datenum(now));

% Save results
save('output\results_Figure5_IT','results','settings','yraw')
